<?php


class v2uploadlogowidget extends CWidget
{
	public $model=null;
	public $name='date';//选择框变量名
	public $value;//初始值
	public $lang = 'zh_cn';//语言
    public $bili='1/1';//比例
    public $width=372;//比例
    public $height=248;//比例
    public $quality=70;//比例
	public function init()
	{
	}
    public function uploadlogo()
    {
        $url = Yii::app()->createUrl('ubutton/v2uploadlogo/logo/').'?bili='.$this->bili.'&width='.$this->width.'&height='.$this->height.'&quality='.$this->quality;

        $form_id = 'v2uploadlogo';

        $title="图片裁剪";

        $label =" 上传图片";
        $iid = $this->name;
        $iname = get_class($this->model).'['.$this->name.']';
        $html="";
        if(!empty($this->model))
        {
            $str=$this->model[$this->name];
        }
        else
        {
            $str='';
        }
        $btn = "<input style='margin: 10px 0 0 10px;' type=\"button\" class=\"default_btn\"  onclick=\"javascript:showUploadLogoBlock('".$this->bili."','".$url."','".$form_id."','".$title."','".$iname."','".$iid."')\" value='".$label."'>";
        $img = '<div style="width:10%;border: solid 1px #555;padding: 5px;margin-top: 10px;float: left;"><img src="/img/'.$str.'" width="100%" id="img-'.$iid.'"></div>';
        $ipt = '<input class="text" style="display:none;" name="'.$iname.'" type="text" value="">';

        echo $img.$btn.$ipt;
        $this->registerClientScript();
    }
	public function run()
	{
        $this->uploadlogo();
    }

    protected  function registerClientScript()
    {
        $cs=Yii::app()->clientScript;
        $cs->registerScriptFile(Yii::app()->request->baseUrl."/public/js/v2uploadlogo/common.js");
    }

}